Skip to content

[2.3] Reworked gallery.phtml to move generation of gallery json strings to own block functions#18440

Merged
magento-engcom-team merged 5 commits into
magento:2.3-developfrom
gwharton:2.3-develop-gallery-rework
Apr 8, 2019
Merged

[2.3] Reworked gallery.phtml to move generation of gallery json strings to own block functions#18440
magento-engcom-team merged 5 commits into
magento:2.3-developfrom
gwharton:2.3-develop-gallery-rework

Conversation

@gwharton

@gwharton gwharton commented Oct 7, 2018

Copy link
Copy Markdown
Contributor

Description

Reworked gallery.phtml to move generation of gallery json strings to own block functions
Introduced unit tests to cover generation of gallery json strings with full type checking.

The resultant code is much easier to diagnose and test. It uses the json_encode and json_decode routines instead of the old manual way of generating json strings that were used in the old gallery.phtml which is prone to error and mistakes.

Fixed Issues (if relevant)

  1. none. Rework and unit tests.

Manual testing scenarios

  1. View source on any product page.
  2. Ensure the gallery section has fully formed json for gallery and gallery fullscreen sections.

Stock Magento should be

"options": {"nav":"thumbs","loop":true,"keyboard":true,"arrows":true,"allowfullscreen":true,"showCaption":false,"width":700,"thumbwidth":88,"thumbheight":110,"height":700,"transitionduration":500,"transition":"slide","navarrows":true,"navtype":"slides","navdir":"horizontal"}

and

"fullscreen": "nav":"thumbs","loop":true,"navdir":"horizontal","navarrows":false,"navtype":"slides","arrows":true,"showCaption":false,"transitionduration":500,"transition":"slide"}

All strings/bools/ints are now typed properly as per the Magento dev docs for the Magento 2 Gallery Widget.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@gwharton

gwharton commented Oct 7, 2018

Copy link
Copy Markdown
Contributor Author

The 2.2 Backport PR is here #18443

@ihor-sviziev ihor-sviziev self-assigned this Oct 8, 2018
Comment thread app/code/Magento/Catalog/Block/Product/View/Gallery.php Outdated
Comment thread app/code/Magento/Catalog/Block/Product/View/Gallery.php Outdated
Comment thread app/code/Magento/Catalog/Block/Product/View/Gallery.php Outdated
Comment thread app/code/Magento/Catalog/Block/Product/View/Gallery.php Outdated
@gwharton gwharton dismissed sidolov’s stale review November 10, 2018 19:35

Changes incorporated

@magento-engcom-team

Copy link
Copy Markdown
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-3987 has been created to process this Pull Request

@sidolov

sidolov commented Mar 5, 2019

Copy link
Copy Markdown
Contributor

Hi @gwharton , it's a really good changes that helps external developers customize gallery configuration, but unfortunately, we are not allowed to add new public methods to blocks that marked as @api.
As alternative solution you may extract logic to the separate class, inject it to block via di configuration and use in the phtml template. You can find the example in the /app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml
Thank you!

@gwharton

gwharton commented Mar 6, 2019

Copy link
Copy Markdown
Contributor Author

@sidolov, Thats neat. I hadn't realised you could do that.

I've updated the 2.3 and 2.2 PR's accordingly. Just waiting on the Travis backlog, but pretty sure they should come in green. If not I will resolve.

Comment thread app/code/Magento/Catalog/Block/Product/View/GalleryOptions.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryOptionsTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php Outdated
Comment thread app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php Outdated
@magento-cicd2

Copy link
Copy Markdown
Contributor

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@gwharton

Copy link
Copy Markdown
Contributor Author

Just waiting on a travis pass.

I have reverted all changes to Gallery.php and GalleryTest.php as all active changes were moved to GalleryOptions.php and GalleryOptionsTest.php and the changes that were left in the original Gallery.php and GalleryTest.php were cleanup code unrelated to this PR and a distraction.

This PR feels much cleaner now.

@magento-engcom-team

Copy link
Copy Markdown
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-3987 has been created to process this Pull Request

@magento-engcom-team

Copy link
Copy Markdown
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-3987 has been created to process this Pull Request

@VasylShvorak

Copy link
Copy Markdown
Contributor

✔️ QA passed

@m2-assistant

m2-assistant Bot commented Apr 8, 2019

Copy link
Copy Markdown

Hi @gwharton, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.2 milestone Apr 8, 2019
magento-engcom-team pushed a commit that referenced this pull request Apr 8, 2019
@gwharton gwharton deleted the 2.3-develop-gallery-rework branch April 23, 2019 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants